package top.toptimus.dto.measure;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 尺寸项目
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class MeasureItemDTO {
    private String itemCd; //  衣服CD
    private String itemValue;  //  衣服VALUE
    @Deprecated
    private String propertyValue;  //  人VALUE
    @Deprecated
    private String fitValue;   //  人尺寸值
    private Double itemFitValue;  //  式样衣尺寸
    private Double inValue;    //  加值
    private Double outValue;   //  减值
    private String itemNameCn;    //  尺寸名称
    private Double garmentSize; //  成衣尺寸
    private Double leastReasonable; //  最小合理值
    private Double maxReasonable;   //  最大合理值
    private Double customerFitValue;  //  客户量体值
    private String id;
    private String parentId;
    private int index;
    private boolean hasFitValue; // 人尺寸值
    private boolean hasGarmentSize;  //    成衣尺寸
    private boolean hasHalf; //  是否有1/2

    public MeasureItemDTO(
            String ITEM_CD
            , String ITEM_VALUE
            , String ITEM_NAME_CN
            , double itemFitValue
            , double garmentSize
            , Double IN_VALUE
            , Double OUT_VALUE
            , String id
            , String parentId
            , int index
            , boolean isFIT_VALUE // 人尺寸值
            , boolean isGarmentSize  //    成衣尺寸
            , boolean isHalf //  是否有1/2
            , Double customerFitValue
    ) {
        this.itemCd = ITEM_CD;
        this.itemValue = ITEM_VALUE;
        this.itemNameCn = ITEM_NAME_CN;
        this.itemFitValue = itemFitValue;
        this.garmentSize = garmentSize;
        this.inValue = IN_VALUE;
        this.outValue = OUT_VALUE;
        this.id = id;
        this.parentId = parentId;
        this.index = index;
        this.hasFitValue = isFIT_VALUE;
        this.hasGarmentSize = isGarmentSize;
        this.hasHalf = isHalf;
        this.customerFitValue = customerFitValue;
    }

    public MeasureItemDTO(
            StyleFitDTO styleFitDTO,
            MeasureItemConfigDTO measureItemConfigDTO
    ) {
        this.itemCd = styleFitDTO.getItemCd();
        this.itemValue = styleFitDTO.getItemValue();
        this.itemNameCn = measureItemConfigDTO.getITEM_NAME_CN();
        this.itemFitValue = styleFitDTO.getFitValue();
        this.garmentSize = styleFitDTO.getGarmentSize();
        this.inValue = styleFitDTO.getInValue();
        this.outValue = styleFitDTO.getOutValue();
        this.id = measureItemConfigDTO.getId();
        this.parentId = measureItemConfigDTO.getParentId();
        this.index = measureItemConfigDTO.getIndex();
        this.hasFitValue = measureItemConfigDTO.isFIT_VALUE();
        this.hasGarmentSize = measureItemConfigDTO.isGarmentSize();
        this.hasHalf = measureItemConfigDTO.isHalf();
    }

    public MeasureItemDTO build(
            MeasureItemDTO measureItemDTO
    ) {
        this.inValue = measureItemDTO.getInValue();
        this.outValue = measureItemDTO.getOutValue();
        this.garmentSize = measureItemDTO.getGarmentSize();
        return this;
    }

    /**
     * 处理二分之一值
     */
    public MeasureItemDTO buildHalf() {
        if (hasHalf) {
            this.inValue = this.inValue / 2;
            this.outValue = this.outValue / 2;
            this.itemFitValue = this.itemFitValue / 2;
            this.garmentSize = this.garmentSize / 2;
        }
        return this;
    }

    /**
     * 计算尺寸
     */
    public void buidCount() {
        this.garmentSize = this.itemFitValue;
        try {
            this.garmentSize += (this.inValue >= 0) ? this.inValue : 0;
        } catch (Exception ignored) {
        }
        try {
            this.garmentSize -= (this.outValue >= 0) ? this.outValue : 0;
        } catch (Exception ignored) {
        }
    }
}
